#!/bin/make
#

#
# commands
#

RM = del /F /Q
AS = ca65
LD = ld65

#
# Flags
#

ASFLAGS = -t vic20 -g  -I .
LDFLAGS = -C vic20-32k.cfg 

#
# Sources
#

CORE_SOURCES = \
	cursor.asm \
	disk.asm \
	drawfun.asm \
	execfun.asm \
	files.asm \
	font4.asm \
	global.asm \
	graphic.asm \
	joymouse.asm \
	keyboard.asm \
	main.asm \
	memory.asm \
	mouse.asm \
	panic.asm \
	petscii.asm \
	prolog.asm \
	screen.asm \
	scrsaver.asm \
	string.asm \
	text.asm \
	timer.asm \
	util.asm \
	window.asm \
	wutil.asm
CORE_OBJECTS = $(patsubst %.asm,%.o,$(CORE_SOURCES))

EXT_SOURCES = \
	extmain.asm \
	msgbox.asm \
	listbox.asm
EXT_OBJECTS = $(patsubst %.asm,%.o,$(EXT_SOURCES))
	

DEMO_SOURCES = \
	demo.asm \
	demopic.asm \
	extstub.asm \
	menubar.asm \
	picture.asm \
	anypic.asm \
	setup.asm
DEMO_OBJECTS = $(patsubst %.asm,%.o,$(DEMO_SOURCES))

VIN_SOURCES = \
	altmenu.asm
VIN_OBJECTS = $(patsubst %.asm,%.o,$(VIN_SOURCES))

DISK_SOURCES = \
	diskmenu.asm \
	dmgui.asm
DISK_OBJECTS = $(patsubst %.asm,%.o,$(DISK_SOURCES))

TARGETS = vin20.prg vindemo.prg diskmenu.prg

#
# targets
#

.PHONY : all clean install

all:	$(TARGETS)

install:	vin20.d64

clean:
	$(RM) $(CORE_OBJECTS) $(EXT_OBJECTS) $(DEMO_OBJECTS) $(VIN_OBJECTS) $(TARGETS) vin20.d64

vin20.prg:		$(CORE_OBJECTS) $(EXT_OBJECTS) $(VIN_OBJECTS)
	$(LD) $(LDFLAGS) -m $(patsubst %.prg,%.map,$@) -Ln $(patsubst %.prg,%.lbl,$@) -o $@ $^
	
vindemo.prg:	$(CORE_OBJECTS) $(DEMO_OBJECTS)
	$(LD) $(LDFLAGS) -m $(patsubst %.prg,%.map,$@) -Ln $(patsubst %.prg,%.lbl,$@) -o $@ $^

diskmenu.prg:	$(CORE_OBJECTS) $(EXT_OBJECTS) $(DISK_OBJECTS)
	$(LD) $(LDFLAGS) -m $(patsubst %.prg,%.map,$@) -Ln $(patsubst %.prg,%.lbl,$@) -o $@ $^

vin20.d64:	blank.d64 diskmenu.prg vindemo.prg
	copy blank.d64 $@
	disktool -a $@ diskmenu diskmenu.prg
	disktool -a $@ vindemo vindemo.prg

#
# Pattern rules
#

.SUFFIXES:
.SUFFIXES: .asm .o

%.o : %.asm
	$(AS) $(ASFLAGS) -o $@ $<
